﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Win32;

namespace DiasEngineDate
{
    /// <summary>
    /// SoftReg.xaml 的交互逻辑
    /// </summary>
    public partial class SoftReg : Window
    {
        public SoftReg()
        {
            InitializeComponent();
        }
        DiasRegister softReg = new DiasRegister();
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (RegCodeNum.Text == softReg.GetRNum())
                {
                    //MessageBox.Show("注册成功！重启软件后生效！", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    SystemInformations si1 = new SystemInformations("注册成功", "感谢您对缔亚引擎的支持？");
                    si1.ShowDialog();
                    RegistryKey retkey = Registry.CurrentUser.OpenSubKey("Software", true).CreateSubKey("Dias").CreateSubKey("Dias.INI").CreateSubKey(RegCodeNum.Text);
                    retkey.SetValue("UserName", "Diasoftware");
                    this.Close();
                }
                else
                {
                    //MessageBox.Show("注册码错误！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    SystemInformations si = new SystemInformations("注册失败", "您输入的注册码不正确？请向软件运营商购买注册码？");
                    si.ShowDialog();
                    RegCodeNum.SelectAll();
                }
            }
            catch (Exception ex)
            {

            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if ((30 - Convert.ToInt32((Int32)Registry.GetValue("HKEY_CURRENT_USER\\SOFTWARE\\Dias", "UseTimes", 0))) > 0)
            {

            }
            else 
            {
                SystemInformations sir = new SystemInformations("权限提醒", "您的使用次数已经达到必须注册才能使用.关闭程式.");
                sir.ShowDialog();
                Application.Current.Shutdown(-1);
                Environment.Exit(0);
            }
        }
    }
}
